$(function() {
    $(".datepicker").datepicker();
    
    $("#add-detail").click(function() {
//js_detail_ini//
        $( "#dialog-modal" ).dialog( "open" );
    });
            
    $( "#save-invoice" ).click(function() {
        var detail=new Array(); 
        var pos = 0;
        $("#detail_table > tbody > tr").each(function() {
            detail[pos] = {
            //js_save_detail//
            };
            pos++;
        });
        $.post("save", {
            //js_save_header// items:pos,
            detail : detail
        } ,
        function(data) {
            alert("Succsess");
            window.location = "index"
        });
            
        
    });
            
    //js_detail//

        
    $("#detail_table tbody").on("click", "#delete", function(event){
    tr = $(this).parent().parent();
    //deleteDetail//
   tr.remove();    
});   
            
    $( "#dialog-modal" ).dialog({
        autoOpen: false,
        height: 355,
        width: 550,
        modal: true,
        buttons: {
            "Insert": function() {                
                //addDetail//
                $( "#detail_table tbody" ).append( "<tr>" +
//js_td_detail//
                    "<td><span  id=\"delete\"><i class=\"icon-remove\"></i>Remove</span></td>" +
                    "</tr>" );                        
                $( this ).dialog( "close" );
            },
            Cancel: function() {
                $( this ).dialog( "close" );
            }
        },
        close: function() {
            $( this ).dialog( "close" );
        }
    });
});



